package com.mxl.user.utils;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.fill.Column;

import java.nio.file.Paths;

/**
 * 代码生成器 使用这个
 * @Author: mxl
 * Date:    2024/07/16 15:01,
 * Version: IntelliJ IDEA 2021.2.1
 *
 */
public class GeneratorTwo {
    public static void main(String[] args) {
        generate();
    }

    private static void generate() {
        FastAutoGenerator.create("jdbc:mysql://36.1.54.31:3306/mxltest?serverTimezone=Asia/Shanghai&useUnicode=true&" +
                        "characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true", "root", "t=j.3lRsdat6")
                .globalConfig(builder -> builder
                        .author("mxl")
                        .outputDir(Paths.get(System.getProperty("user.dir")) + "/service/user/src/main/java")
                        .commentDate("yyyy-MM-dd")
                )
                .packageConfig(builder -> builder
                        .parent("com.mxl.user")
                        .entity("entity")
                        .mapper("mapper")
                        .service("service")
                        .serviceImpl("service.impl")
                        .xml("mapper.xml")
                )
                .strategyConfig(builder -> builder
                        .addInclude("user") // 设置需要生成的表名 !!!
                        .entityBuilder()
                        .enableLombok()
                        .addTableFills(
                                new Column("create_time", FieldFill.INSERT),
                                new Column("update_time", FieldFill.INSERT_UPDATE)
                        )   //添加表字段填充，"create_time"字段自动填充为插入时间，"modify_time"字段自动填充为插入修改时间

                )
//                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}